Linux chage 命令初学者教程(6 个示例) 您所在的位置:网站首页 Linux exit 命令初学者讲解附实例 Linux chage 命令初学者教程(6 个示例)

Linux chage 命令初学者教程(6 个示例)

2024-06-27 04:04| 来源: 网络整理| 查看: 265

Linux chage 命令初学者教程(6 个示例) 在此页

Linux chage 命令 Q1。如何查看当前密码过期信息? Q2。如何修改密码有效期? Q3。如何更改上次密码更改日期? Q4。如何在密码过期前警告用户? Q5。如何锁定账户? Q6。如果在没有任何选项的情况下使用 chage 会发生什么? 结论

Linux 命令行提供了多种用户管理工具(我们已经讨论过其中一些)。其中一个实用程序是 chage,它可以让您调整密码到期信息。在本教程中,我们将使用一些易于理解的示例来讨论此工具。但在我们深入之前,值得一提的是,这里的所有示例都已经在 Ubuntu 18.04 LTS 机器上进行了测试。

Linux 更改命令

如上所述,chage 命令允许您调整用户密码到期信息。以下是它的语法:

chage [options] LOGIN

这是手册页中关于它的内容:

The chage command changes the number of days between password changes       and the date of the last password change. This information is used by       the system to determine when a user must change his/her password.

以下是一些 Q&A 风格的示例,应该可以让您对 chage 命令的工作原理有一个很好的了解:

Q1。如何查看当前密码过期信息?

要查看用户的当前密码到期日期信息,请使用 -l 命令行选项。

chage -l [USERNAME]

这是一个例子:

chage -l himanshu

以下是它在我的系统上产生的输出:

Last password change                    : Jul 26, 2018Password expires                     : neverPassword inactive                    : neverAccount expires                        : neverMinimum number of days between password change        : 0Maximum number of days between password change        : 99999Number of days of warning before password expires    : 7

所以目前,密码设置为永不过期。

Q2。如何修改密码有效期?

您可以使用 -M 命令行选项执行此操作,该选项要求您传递一个数字(指密码有效的最大天数)。

例如:

chage -M 1000 himanshu

请注意,此操作需要 root 权限。

所以你可以在上面的屏幕截图中看到,密码到期时间现在已设置为 2021 年 4 月 21 日。

请注意,您还可以使用 -m 命令行选项,该选项用于设置密码更改之间的最小天数。我们上面讨论的 -M 选项设置密码有效的最大天数。

Q3.如何更改上次密码更改日期?

您可以使用 -d 命令行选项调整上次密码更改日期。作为输入,您可以将数字或完整日期传递给此选项。手册页是这样解释的:

-d, --lastday LAST_DAY           Set the number of days since January 1st, 1970 when the password           was last changed. The date may also be expressed in the format           YYYY-MM-DD (or the format more commonly used in your area).

下面是一个例子:

所以可以看到 Last password change 字段的值修改成功。

Q4.如何在密码过期前警告用户?

chage 命令还允许您设置在需要更改密码之前发出警告的天数。这可以使用 -W 命令行选项来完成。

-W, --warndays WARN_DAYS           Set the number of days of warning before a password change is           required. The WARN_DAYS option is the number of days prior to the           password expiring that a user will be warned his/her password is           about to expire.

例如:

chage -W 10 himanshu

此命令将确保用户在密码设置为过期前 10 天看到密码过期警告。

Q5.如何锁定账户?

使用 -E 命令行选项锁定帐户。它接受输入的方式类似于我们上面讨论的 -W 选项。供您参考,以下是手册页的解释:

-E, --expiredate EXPIRE_DATE           Set the date or number of days since January 1, 1970 on which the           user's account will no longer be accessible. The date may also be           expressed in the format YYYY-MM-DD (or the format more commonly           used in your area). A user whose account is locked must contact the           system administrator before being able to use the system again.

           Passing the number -1 as the EXPIRE_DATE will remove an account           expiration date.

例如:

chage -E 2019-06-21 himanshu

上述命令将确保用户 himanshu 的帐户从 2019 年 6 月 21 日开始无法访问。

Q6.如果在没有任何选项的情况下使用 chage 会发生什么?

在这种情况下会发生以下情况:

If none of the options are selected, chage operates in an interactive       fashion, prompting the user with the current values for all of the       fields. Enter the new value to change the field, or leave the line       blank to use the current value. The current value is displayed between       a pair of [ ] marks.结论

如果您是 Linux 系统管理员,或者负责 Linux 机器上的用户管理的人员,那么这个命令值得您收藏。我们在这里介绍了几个 chage 命令行选项。要了解更多信息,请访问 chage 手册页。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有